package mylib.archive.y2012.m09.CF138;

import mylib.dir.FastInputReader;

import java.io.PrintWriter;

public class TaskA {
    public void solve(int testNumber, FastInputReader in, PrintWriter out) {
        char[] s = in.nextString().toCharArray();
        int n = s.length;
        int[] st = new int[n];
        int ptr = 0;
        boolean pair[] = new boolean[n];
        for (int i = 0; i < n; ++i) {
            if (s[i] == '(' || s[i] == '[') {
                st[ptr++] = i;
            } else {
                if (ptr >= 1 && ((s[st[ptr - 1]] == '(' && s[i] == ')') || (s[st[ptr - 1]] == '[' && s[i] == ']'))) {
                    pair[i] = pair[st[ptr - 1]] = true;
                    --ptr;
                } else {
                    ptr = 0;
                }
            }
        }
//        out.println(Arrays.toString(pair));
        int best = 0, l = 0, r = -1;
        for (int i = 0, j; i < n; i = j) {
            if (!pair[i]) {
                j = i + 1;
                continue;
            }
            for (j = i; j < n && pair[j]; ++j) ;
            int cnt = 0;
            for (int u = i; u < j; ++u) {
                cnt += s[u] == '[' ? 1 : 0;
            }
            if (best < cnt) {
                best = cnt;
                l = i;
                r = j - 1;
            }
        }
        out.println(best);
        out.print(new String(s).substring(l, r + 1));
    }
}
